package org.jogdiary2011.controller.person;


import org.jogdiary2011.meta.PersonMeta;
import org.jogdiary2011.model.Person;
import org.jogdiary2011.service.PersonService;
import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.util.RequestMap;

public class UpdateController extends Controller {
    
    PersonService personService = new PersonService();
    PersonMeta personMeta = PersonMeta.get();

    @Override
    public Navigation run() throws Exception {
        if (!validate()) {
            return forward("edit.jsp");
        }
        Person person = personService.update(asKey(personMeta.key), asLong(personMeta.version), new RequestMap(request));
        sessionScope("person", person);
        return redirect("/person/result");
    }
    
    private boolean validate() {
        return true; // TODO 
    }
}
